/* 上传文件 */
import {useEffect, useState} from "react";

const formData = new FormData();
formData.append("username", "moontahoe");
formData.append("fullname", "Alex banks");
// formData.append("avatar", imgFile);

// fetch("/create/user" ,{
//     method: "POST",
//     body: formData
// })

/* 授权请求 */
// fetch(`https://api.github.com/users/${login}`, {
//     method: "POST",
//     headers: {
//         Authorization: `Bearer ${token}`
//     }
// })

/* 本地保存数据 */
const loadJSON = key => key && JSON.parse(localStorage.getItem(key));
const saveJSON = (key, data) => localStorage.setItem(key, JSON.stringify(data));

export function GitHubUser(){
    const [data, setData] = useState();
    const [error, setError] = useState();
    const [loading, setLoading] = useState(false);

    useEffect(() => {
        if (!data) return;
    }, [data]);

    useEffect(() => {
        // if (!login)  return;
        setLoading(true);
        // if (data && data.login === login) return;

        fetch(`https://api.github.com/users/amlei`)
            .then(response => response.json())
            .then(setData)
            .then(() => setLoading(false))
            .catch(setError);

    }, []);

    if (loading) return <h1>loading...</h1>
    // if (error) return <pre>{JSON.stringify(data, null, 2)}</pre>
    if (!data) return null;
    console.log(data)
    return (
        <div>
            <h1>amlei</h1>
            {data.name && <p>{data.name}</p>}
            {data.bio && <p>{data.bio}</p>}
        </div>
    )
}

/* 处理请求状态 */



